/*!
 * \file __frproto_cfg_get_param.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "frlist.h"
#include "frproto_mng.h"
#include "apmtest_cunit.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{
//    frmodule_mng_init();
    return 0;
}

static int __suite_cleanup(void)
{
//    frmodule_mng_destory();
    return 0;
}

int __frproto_cfg_get_param(char *p_token_protocol
        , u_short *p_us_proto
        , u_int *p_ui_ip
        , u_short *p_us_port_start
        , u_short *p_us_port_end
        , int *p_i_l7_proto);

static void __case1(void)
{
    int i_ret = 0;
    char *p_token_protocol = (char *)frstrdup((char *)"tcp:192.168.1.1:40-80:1");
    u_short us_proto = 0;
    u_int ui_ip = 0;
    u_short us_port_start = 0;
    u_short us_port_end = 0;
    int i_l7_proto = 0;

    i_ret = __frproto_cfg_get_param(p_token_protocol, &us_proto, &ui_ip
            , &us_port_start, &us_port_end, &i_l7_proto);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
    CU_ASSERT_EQUAL(us_proto,IPPROTO_TCP);
    CU_ASSERT_EQUAL(ui_ip, 16885952);
    CU_ASSERT_EQUAL(us_port_start, 40);
    CU_ASSERT_EQUAL(us_port_end, 80);
    CU_ASSERT_EQUAL(i_l7_proto, 1);

    frfree(p_token_protocol);
    return;

}

static void __case2(void)
{
    int i_ret = 0;
    char *p_token_protocol = NULL;
    u_short us_proto = 0;
    u_int ui_ip = 0;
    u_short us_port_start = 0;
    u_short us_port_end = 0;
    int i_l7_proto = 0;

    i_ret = __frproto_cfg_get_param(p_token_protocol, &us_proto, &ui_ip
            , &us_port_start, &us_port_end, &i_l7_proto);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

    return;

}


int add_suite___frproto_cfg_get_param(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frproto_mng __frproto_cfg_get_param()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);
//    CU_add_test(pSuite, "case3", __case3);
//    CU_add_test(pSuite, "case4", __case4);
//    CU_add_test(pSuite, "case5", __case5);

    return FR_SUCC;
}
